package com.water.wl.newwater.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.water.wl.newwater.R;
import com.water.wl.newwater.bean.Tweet;
import com.water.wl.newwater.bean.Tweet1;
import com.water.wl.newwater.widget.AvatarView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wds1993225 on 2016/3/10.
 */
public class TweetAdapter extends ArrayAdapter<Tweet> {

    private int resourceId;

    private Bitmap recordBitmap;

    protected ArrayList<Tweet> mDatas = new ArrayList<Tweet>();

    public TweetAdapter(Context context, int resource, Tweet[] objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    public TweetAdapter(Context context, int resource, List<Tweet> objects) {
        super(context, resource, objects);
    }
    public void addData(List<Tweet> data) {
        if (mDatas != null && data != null && !data.isEmpty()) {
            mDatas.addAll(data);
        }
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.i("当前的位置为",""+position);
        Tweet tweet = mDatas.get(position);
        //Tweet tweet = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,null);
        TextView author = (TextView)view.findViewById(R.id.tv_tweet_name);

        AvatarView face =(AvatarView)view.findViewById(R.id.iv_tweet_face);

        ImageView image = (ImageView)view.findViewById(R.id.iv_tweet_image);
        face.setUserInfo(tweet.getAuthorid(), tweet.getAuthor());
        face.setAvatarUrl(tweet.getPortrait());
        author.setText(tweet.getAuthor());


        return view;
    }
   /* private void initRecordImg(Context cxt) {
        recordBitmap = BitmapFactory.decodeResource(cxt.getResources(),
                R.drawable.audio3);
        recordBitmap = ImageUtils.zoomBitmap(recordBitmap,
                DensityUtils.dip2px(cxt, 20f), DensityUtils.dip2px(cxt, 20f));
    }*/
}
